import {createSlice, PayloadAction} from "@reduxjs/toolkit";
import {GlobalState} from "@/store/interface";

const initialState: GlobalState = {
    // antd 组件尺寸 ("small" | "middle" | "large")
    componentSize: "middle",
    // antd 紧凑型主题
    compactAlgorithm: false,
    // antd 边框圆角
    borderRadius: 6,
    // 当前页面是否全屏
    maximize: false,
    // 主题颜色
    primary: '#1677ff',
    // 夜间模式
    isDark: false,
    // antd 组件喝彩反馈效果
    isHappy: true,
    //菜单手风琴模式
    accordion: true,
    // 是否展示面包屑导航
    breadcrumb: true,
    // 是否展示面包屑导航图标
    breadcrumbIcon: true,
    // 是否展示标签导航
    tabs: true,
    // 是否展示标签导航图标
    tabsIcon: true,
    // 标签是否支持拖拽
    tabsDrag: true,
};

const globalSlice = createSlice({
    name: "global",
    initialState,
    reducers: {
        setGlobalState<T extends keyof GlobalState>(state: GlobalState, {payload}: PayloadAction<ObjToKeyValUnion<GlobalState>>) {
            state[payload.key as T] = payload.value as GlobalState[T];
        }
    }
});

export const {setGlobalState} = globalSlice.actions;
export default globalSlice.reducer;
